package com.zzw.zim.system.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzw.zim.system.dto.AddSysRoleDTO;
import com.zzw.zim.system.dto.EditSysRoleDTO;
import com.zzw.zim.system.dto.QueryRolePageDTO;
import com.zzw.zim.system.entitys.SysRoleEntity;
import com.zzw.zim.system.dao.SysRoleDao;
import com.zzw.zim.system.service.SysRoleService;
import com.zzw.zim.system.vo.SysRoleVo;
import org.springframework.stereotype.Service;

import java.util.UUID;


@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleDao, SysRoleEntity> implements SysRoleService {

    @Override
    public String savaRole(AddSysRoleDTO dto) {
        SysRoleEntity entity = new SysRoleEntity();
        BeanUtil.copyProperties(dto,entity);
        entity.setId(UUID.randomUUID().toString().replace("-",""));
        baseMapper.insert(entity);
        return String.format("新增角色成功，角色名称：%s",entity.getName());
    }

    @Override
    public String editRole(EditSysRoleDTO dto) {
        SysRoleEntity entity = new SysRoleEntity();
        BeanUtil.copyProperties(dto,entity);
        return baseMapper.updateById(entity)==1?"更新成功":"更新失败";
    }

    @Override
    public Page<SysRoleVo> queryRolePage(QueryRolePageDTO dto) {
        Page<SysRoleVo> page = new Page<>(dto.getPage(), dto.getSize());
        page=baseMapper.selectByPage(page,dto);
        return page;
    }

    @Override
    public SysRoleVo queryInfo(String id) {
        SysRoleEntity entity = baseMapper.selectById(id);
        SysRoleVo vo = new SysRoleVo();
        BeanUtil.copyProperties(entity,vo);
        return vo;
    }
}
